package com.design.model.mediator;

/**
 * @program: study
 * @className: ConcreteMediator
 * @description: TODO
 * @author: kukuxiahuni
 * @create: 2019-06-27 16:56
 * @version: v1.0
 **/
public class ConcreteMediator extends Mediator {

    private ConcreteColleagueA concreteColleagueA;
    private ConcreteColleagueB concreteColleagueB;

    public void setConcreteColleagueA(ConcreteColleagueA concreteColleagueA) {
        this.concreteColleagueA = concreteColleagueA;
    }

    public void setConcreteColleagueB(ConcreteColleagueB concreteColleagueB) {
        this.concreteColleagueB = concreteColleagueB;
    }

    @Override
    public void send(String message, Colleague colleague) {

        if (colleague == this.concreteColleagueA) {
            this.concreteColleagueB.notify(message);
        } else {
            this.concreteColleagueA.notify(message);
        }

    }

    public static void main(String[] args) {
        ConcreteMediator mediator = new ConcreteMediator();

        ConcreteColleagueB concreteColleagueB = new ConcreteColleagueB(mediator);
        ConcreteColleagueA concreteColleagueA = new ConcreteColleagueA(mediator);

        mediator.setConcreteColleagueA(concreteColleagueA);
        mediator.setConcreteColleagueB(concreteColleagueB);

        concreteColleagueA.send("我是pig");
        concreteColleagueB.send("我是狗狗");
    }
}
